package su.msk.jet.team01.chatik.client;

import java.io.IOException;

import su.msk.jet.team01.chatik.client.ui.UserInterface;

public class UIOutputHandler extends Thread {

	private ClientApplication app;
	private UserInterface ui;

	public UIOutputHandler(final ClientApplication app, final UserInterface ui) {
		this.app = app;
		this.ui = ui;
	}

	@Override
	public void run() {

		try {
			while (true) {
				String messageIn = (String) app.input().readObject();
				ui.printMessage(messageIn);
			}
		} catch (IOException e) {

		} catch (ClassNotFoundException e) {
			ui.printMessage("Unknown class received. It seems that server and client versions are not compatible.");
		} finally {
			app.close();
		}
	}
}
